var express = require('express');

var router = express.Router();

const positionController = require('../controller/position');

const multer = require('multer');

const path = require('path');

// 图片上传并保存在后端的服务器中

var storage = multer.diskStorage({
    destination: function(req, file, cb) {
        cb(null, path.join(__dirname, '../public/upload')) //设置存放文件路径
    },
    filename: function(req, file, cb) {
        let fileSuffixes = '.' + (file.originalname).split('.')[(file.originalname).split('.').length - 1]; //获取图片后缀
        req.fileName = file.fieldname + '-' + Date.now() + fileSuffixes;
        cb(null, file.fieldname + '-' + Date.now() + fileSuffixes); //拼接文件名
    }
});

var upload = multer({ storage: storage });

router.route('/add')
    .post(upload.single('companyLogo'), (req, res, next) => {
        positionController.add({ req, res, next, router });
    })
    .get(function(req, res, next) {
        res.send('get');
        // send是发送字符,render是发送页面
    });

router.route('/find')
    .get((req, res, next) => {
        positionController.find({ req, res, next });
    });

router.route('/remove')
    .delete((req, res, next) => {
        positionController.remove({ req, res, next });
    })
module.exports = router;